#include <bits/stdc++.h>
using namespace std;
int map1[5][17];
int num[5];
int s[17]= {0,-50,-2,-3,-4,-5,-6,-7,-8,-9,-10,-20,-30,-40,-100,100};
int main()
{
    for(int i = 1; i <= 4; i++)
    {
        cin >> num[i];
        for(int j = 1, p; j <= num[i]; j++)
        {
            char k;
            cin >> k >> p;
            if(k == 'H')
                map1[i][p] = 1;
            if(k == 'S')
                map1[i][14] = 1; 
            if(k == 'D')
                map1[i][15] = 1;
            if(k == 'C')
                map1[i][16] = 1;
        }
        int sum = 0, allh = 1;
	    for(int j = 1; j <= 13 && allh; i++)
	        allh = map1[i][j];
	    if(allh)
	    {
	        sum = 200;
	        if(map1[i][14] && map1[i][15])
	            sum = 500;
	        else
	            sum += map1[1][14] * s[14] + map1[i][15] * s[15];
	        cout << (map1[i][16] ? sum << 1 : sum) << endl;
	    }
	    bool c = true;
		for (int j = 1; j <= 15 && c; j++) {
		    c = !map1[i][j];
		}
		
		if (c) {
		    cout << (map1[i][16] ? 50 : 0);
		} else {
		    for (int j = 1; j <= 15; j++) {
		        sum += map1[i][j] * s[j];
		    }
		    cout << (map1[i][16] ? (sum << 1) : sum);
		}

    }
    
    return 0;
}   
